/*
 * PGrid.java
 *
 * Abstract base class for Crypt grid structure.
 */

package sim;

import java.util.ArrayList;
import java.util.HashMap;

abstract public class PGrid {  
    protected Crypt _crypts[];
    protected CryptFactory _factory;
    abstract public ArrayList<Integer> getNeighbors(int n);
    abstract public double getMaxX();         // width of 2d plane
    abstract public double getMaxY();         // height of 2d plane
    abstract public double getX(int n);       // returns the x-coordinate of crypt n on a plane
    abstract public double getY(int n);       // returns the y-coordinate of crypt n on a plane
    abstract public Crypt getCryptAtCenter(); // returns the crypt at the center of the Grid

    abstract public int getWidth();

    abstract public int getHeight();




    // Clone frequencies
    public HashMap<Integer,Float> _cloneFrequency; // stores the number of clones
    
    public float getCloneFrequency(int clone_id){
	Float res = _cloneFrequency.get(clone_id);
	if(res==null) return 0.0f;
	else return res.floatValue();
    }
    
    // returns the # of crypts
    public int getSize() { return _crypts.length; }
    
    // returns a single crypt
    public Crypt getCrypt(int x) {
	if (x < getSize())
	    return _crypts[x];
	else
	    return null;
    }

    abstract public void setRandomCryptNeighborsWithinRadius(int n, int k, int r);
    

	
    
    // returns crypts in a circular region with radius r, centered at (x,y)
    public ArrayList<Crypt> getCryptsInCircle(double x, double y, double r) {
	ArrayList<Crypt> list = new ArrayList<Crypt>();		
	for(int i=0; i<_crypts.length; i++ )
	    if (Math.hypot(getX(i)-x, getY(i)-y)<=r)
		list.add(_crypts[i]);
	return list;
    }
}
